package com.breaktian.network.http;

import android.os.Build;
import android.text.TextUtils;
import android.util.ArrayMap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import okhttp3.Headers;

/**
 * Created by keke.tian on 2018/4/3.
 */

public class HttpHeader {
    Map<String,String> headers;

    public HttpHeader(){
        headers = new HashMap<>();
    }


    HttpHeader add(String key, String value) {
        if (TextUtils.isEmpty(key)) throw new IllegalArgumentException("key cannot be null");
        headers.put(key, value);
        return this;
    }

    HttpHeader merge(HttpHeader header) {
        if (header == null) return this;
        return merge(header.headers);
    }

    HttpHeader merge(Map<String, String> headers) {
        if (headers != null && headers.size() > 0) {
            Set<String> keys = headers.keySet();
            for (String key : keys) {
                if (!this.headers.containsKey(key)) {
                    this.headers.put(key, headers.get(key));
                }
            }
        }

        return this;
    }

    Headers convert() {
        return Headers.of(headers);
    }


}
